﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NetCoreCMS.IServices;
using NetCoreCMS.Models;

namespace NetCoreCMS.Web.Areas.WebApi.Controllers
{
    public class User_ShopController : UserController
    {
        public IShopService _shop { get; set; }
        [Authorize]
        [HttpGet]
        public IActionResult Get()
        {
            //检查用户是否登录
            Users userModel = GetUserInfo();
            if (userModel == null)
            {
                return Ok(new { status = 0, msg = "用户尚未登录或已超时！" });
            }
            var shop = _shop.GetFirstByUserId(userModel.id);
            var sys = Common.XMLConfig.Sysconfig.loadConfig(_env.ContentRootPath);
            shop.img_url = sys.weburl + shop.img_url;
            for (int i = 0; i < shop.albums.Count; i++)
            {
                shop.albums[i].original_path = sys.weburl + shop.albums[i].original_path;
                shop.albums[i].thumb_path = sys.weburl + shop.albums[i].thumb_path;
            }
            return Ok(new { status = 1, data = shop });
        }
    }
}